package com.wlz.utils;

import java.security.SecureRandom;
import java.util.Random;

/**
 * @author ：Administrator
 * @date ：2018/10/15/015 14:09
 */


public class MessageCodeUtils {
    private static final String SYMBOLS = "0123456789";
    private static final Random RANDOM = new SecureRandom();

    public static String getCode() {

        // 如果需要4位，那 new char[4] 即可，其他位数同理可得
        char[] nonceChars = new char[6];

        for (int index = 0; index < nonceChars.length; ++index) {
            nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
        }

        return new String(nonceChars);
    }


}
